define(['vue','common','ELEMENT'],function (Vue,common,ELEMENT){
    const {createApp} = Vue;
    const {ElMessageBox} = ELEMENT;
    const Controller = {
        index:function (){
            let app = createApp({
                data(){
                    return {
                        upfile_path:"/app/muadmin/admin/ajax/upload",
                        //列表数据
                        listObj:{
                            page:1,
                            limit:10,
                            total:0,
                            list:[]
                        },
                        //搜索条件
                        search:{
                            list:[
                                {
                                    lable:"名称",
                                    inputType:'text',
                                    name:"title",
                                    operate:"LIKE",
                                    value:""
                                },
                                {
                                    lable:"包名称",
                                    inputType:'text',
                                    name:"key",
                                    operate:"LIKE",
                                    value:""
                                }
                            ],
                            form:{
                                filter:[],
                                op:[],
                                pk:"id",
                                sort:'id',
                                order:"asc"
                            }
                        },
                        //批量选择
                        selectables:[]
                    }
                },
                created(){
                    this.getList()
                    console.log(this.listObj)
                },
                methods:{
                    ...common,
                    handleDelete(row,pk='id'){
                        if(this.search?.form?.pk){
                            pk = this.search.form.pk
                        }
                        let ids = ""
                        if((typeof row)=='string'||(typeof row)=='number'){
                            ids = row
                        }
                        if(Array.isArray(row)){
                            ids = row.map(item=>item[pk]).join(',')
                        }else if((typeof row)=='object'){
                            ids = row[pk]
                        }
                        if(!ids){
                            common.message('请选择要卸载的项')
                            return
                        }
                        let that = this;
                        ElMessageBox({
                            title: '提示',
                            message: '确定要卸载吗？',
                            type: 'warning',
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            showCancelButton:true,
                            callback: (action) => {
                                console.log(action)
                                if (action === 'confirm') {
                                    let url = common.getHandleUrl('del')
                                    common.post(url,{ids:ids}).then(res=>{
                                        if(res.code==1){
                                            that.success(res.msg)
                                            that.getList();
                                        }else{
                                            that.error(res.msg)
                                        }
                                    })
                                }
                            }
                        })
                    },
                    handleLocation(response){
                        console.log(response)
                    }
                }
            })
            common.load(app,['icon','MuForm'])
            app.mount('#app')
        },
        add:function (){
            let app = createApp({
                data(){
                    return {
                        form:{
                            title:"",
                            key:"",
                            description:"",
                            require:[],
                            version:"1.0.0",
                            status:1
                        },
                        rules:{
                            key:[
                                { required: true, message: '请输入用户名', trigger: 'blur' }
                            ],
                            title: [
                                { required: true, message: '请输入密码', trigger: 'blur' }
                            ],
                        },
                        options:{
                            requireList:[]
                        }
                    }
                },
                created(){
                    this.options.requireList = Config.pluginList
                    console.log(this.options,'tttttttttttttttt')
                },
                methods:{
                    ...common,
                    handleCheck(){
                        let url = common.getHandleUrl('check')
                        let that = this
                        common.postHandle(url,{key:this.form.key}).then(res=>{
                            that.success("可以使用")
                        })
                    }
                }
            })
            common.load(app,['icon','MuForm',])
            app.mount('#app')
        },
        location:function (){
            let app = createApp({
                data(){
                    return {
                        form:{
                           file_path:""
                        }
                    }
                },
                methods:{
                    onSubmit(){
                        if(!this.form.key){
                            common.message('请输入key')
                            return
                        }
                        let url = common.getHandleUrl('check')
                        let that = this
                        common.postHandle(url,{key:this.form.key}).then(res=>{})
                    }
                }
            })
            common.load(app,['icon','MuFileUpload'])
            app.mount('#app')
        }
    }
    return Controller
})